package com.swanclouds.redfish.systems.domain;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonRootName;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.swanclouds.redfish.common.redfish.*;
import com.swanclouds.redfish.common.utils.StringHepler;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 系统资源信息
 *
 * @author 张立强
 */
public class Systems {
//    /**
//     * 系统资源的访问路径
//     */
//    @JsonProperty("@odata.id")
//    private String dataId;
//
//    /**
//     * 系统资源模型的OData描述信息
//     */
//    @JsonProperty("@odata.context")
//    private String context;
//
//    /**
//     * 系统资源的类型
//     */
//    @JsonProperty("@odata.type")
//    private String type;

    /**
     * 系统资源的ID
     */
    @JsonProperty("Id")
    private String id;

    /**
     * 系统资源的名称
     */
    @JsonProperty("Name")
    private String name;

    /**
     * Redfish 允许的系统资源可执行的操作
     */
    @JsonProperty("Actions")
    private Actions action;

    /**
     * 系统资源的资产编码
     */
    @JsonProperty("AssetTag")
    private String assetTag;

    /**
     * 统资源的制造商
     */
    @JsonProperty("Manufacturer")
    private String manufacturer;

    /**
     * 系统资源型号
     */
    @JsonProperty("Model")
    private String model;

    /**
     * 系统资源的序列号
     */
    @JsonProperty("SerialNumber")
    private String serialNumber;

    /**
     * 系统资源的全球唯一标识
     */
    @JsonProperty("UUID")
    private String UUID;

    /**
     * 系统资源的部件号
     */
    @JsonProperty("PartNumber")
    private String partNumber;

    /**
     * 系统资源的主机名
     */
    @JsonProperty("HostName")
    private String hostName;

    /**
     * 系统资源的主机角色[ApplicationServer, Switch, StorageServer]
     */
    @JsonProperty("HostingRole")
    private List<String> hostingRole;
    /**
     * 定系统资源的类型
     */
    @JsonProperty("SystemType")
    private String systemType;

    /**
     * 系统资源的上电状态[On,Off]
     */
    @JsonProperty("PowerState")
    private String powerState;

    /**
     * 系统资源的状态
     */
    @JsonProperty("Status")
    private Status status;

    /**
     * 定系统资源掉电恢复策略
     */
    @JsonProperty("PowerRestorePolicyType")
    private String powerRestorePolicyType;
    /**
     * 定位指示灯的状态 [Lit,Off,Blinking]
     */
    @JsonProperty("IndicatorLED")
    private String indicatorLED;

    /**
     * 系统资源的启动参数
     */
    @JsonProperty("Boot")
    private Boot boot;

    /**
     * 系统资源的BIOS版本
     */
    @JsonProperty("BiosVersion")
    private String biosVersion;

    @JsonProperty("BIOSVersion")
    private String biosVersion1;

    /***
     * 指定系统资源的可信模块
     * 说明
     * iBMC 3.49以前版本为对象类型
     * iBMC 3.49及以后版本修正为数组类型
     */
    @JsonProperty("TrustedModules")
    private Object trustedModules;

    /**
     * 系统资源的CPU信息
     */
    @JsonProperty("ProcessorSummary")
    private ProcessorSummary processorSummary;

    /**
     * 系统资源的内存信息
     */
    @JsonProperty("MemorySummary")
    private MemorySummary memorySummary;

    /**
     * 自定义属性信息
     */
    @JsonProperty("Oem")
    private SystemsOem oem;

    @JsonProperty("Processors")
    private MemberModel processors;

    @JsonProperty("Memory")
    private MemberModel memory;

    @JsonProperty("Storage")
    private MemberModel storage;

    @JsonProperty("Bios")
    private MemberModel bios;

    @JsonProperty("NetworkInterfaces")
    private MemberModel networkInterfaces;

    @JsonProperty("LogServices")
    private MemberModel logs;


    @JsonProperty("PCIeFunctions")
    private List<MemberModel> PCIeFunctions;

    @JsonProperty("PCIeDevices")
    private List<MemberModel> PCIeDevices;
    /**
     * 系统资源的制造商
     *
     * @return manufacturer
     */
    
    public String getManufacturer() {
        return this.manufacturer;
    }

    /**
     * 系统资源型号
     *
     * @return model
     */
    
    public String getModel() {
        return this.model;
    }

    /**
     * 系统资源的序列号
     *
     * @return serialNumber
     */
    
    public String getSerialNumber() {
        return this.serialNumber;
    }

    /**
     * Redfish 允许的系统资源可执行的操作
     *
     * @return action
     */
    
    public Actions getAction() {
        return this.action;
    }

    /**
     * 系统资源的资产编码
     *
     * @return assetTag
     */
    
    public String getAssetTag() {
        return this.assetTag;
    }

    /**
     * 系统资源的全球唯一标识
     *
     * @return UUID
     */
    
    public String getUUID() {
        return this.UUID;
    }

    /**
     * 系统资源的主机角色
     *
     * @return HostingRole
     */
    
    public List<String> getHostingRole() {
        return this.hostingRole;
    }

    /**
     * 系统资源的主机名
     *
     * @return hostName
     */
    
    public String getHostName() {
        return this.hostName;
    }

    /**
     * 系统资源的上电状态
     *
     * @return powerState
     */
    
    public String getPowerState() {
        return this.powerState;
    }

    
    public Object getTrustedModules() {
        return this.trustedModules;
    }

    public String getPartNumber() {
        return partNumber;
    }

    public String getSystemType() {
        return systemType;
    }

    public Status getStatus() {
        return status;
    }

    public String getPowerRestorePolicyType() {
        return powerRestorePolicyType;
    }

    public String getIndicatorLED() {
        return indicatorLED;
    }

    public Boot getBoot() {
        return boot;
    }

    public ProcessorSummary getProcessorSummary() {
        return processorSummary;
    }

    public MemorySummary getMemorySummary() {
        return memorySummary;
    }

    public SystemsOem getOem() {
        return oem;
    }

    
    public String getBiosVersion() {
        return StringHepler.isNotBlank(this.biosVersion) ? this.biosVersion : StringHepler.isNotBlank(this.biosVersion1) ? this.biosVersion1 : null;
    }

    
    public List<String> getPCIeFunctions() {
        List<String> PCIeFunctionList = new ArrayList<>();
        if (this.PCIeFunctions != null && this.PCIeFunctions.size() > 0) {
            this.PCIeFunctions.stream().forEach(fuction -> {
                PCIeFunctionList.add(fuction.getDataId());
            });
        }
        return PCIeFunctionList;
    }

    
    public List<String> getPCIeDevices() {
        return this.PCIeDevices.stream().map(MemberModel::getDataId).collect(Collectors.toList());
    }

    
    public Boolean supportProcessorService() {
        return processors != null && StringHepler.isNotBlank(processors.getDataId());
    }

    
    public Boolean supportMemoryService() {
        return memory != null && StringHepler.isNotBlank(memory.getDataId());
    }

    
    public Boolean supportStorageService() {
        return storage != null && StringHepler.isNotBlank(storage.getDataId());
    }

    
    public Boolean supportBiosService() {
        return bios != null && StringHepler.isNotBlank(bios.getDataId());
    }

    
    public Boolean supportEthernetInterfaceService() {
        return false;
    }

    
    public Boolean supportNetworkInterfaceService() {
        return networkInterfaces != null && StringHepler.isNotBlank(networkInterfaces.getDataId());
    }

    
    public Boolean supportLogServices() {
        return logs != null && StringHepler.isNotBlank(logs.getDataId());
    }

//    /**
//     * 系统资源的访问路径 @odata.id
//     *
//     * @return dataId
//     */
//    
//    public String getDataId() {
//        return this.dataId;
//    }
//
//    /**
//     * 系统资源模型的OData描述信息 @odata.context
//     *
//     * @return context
//     */
//    
//    public String getContext() {
//        return this.context;
//    }
//
//    /**
//     * 系统资源的类型 @odata.type
//     *
//     * @return type
//     */
//    
//    public String getType() {
//        return this.type;
//    }

    /**
     * 系统资源的ID Id
     *
     * @return id
     */
    
    public String getId() {
        return this.id;
    }

    /**
     * 系统资源的名称 Name
     *
     * @return name
     */
    
    public String getName() {
        return this.name;
    }

    
    public String toString() {
        ObjectMapper objectMapper = new ObjectMapper();
        try {
            return objectMapper.writeValueAsString(this);
        } catch (JsonProcessingException e) {
        }
        return "Systems {" +
//                "dataId='" + dataId + '\'' +
//                ", context='" + context + '\'' +
//                ", type='" + type + '\'' +
                " id='" + id + '\'' +
                ", name='" + name + '\'' +
                ", action=" + action +
                ", assetTag='" + assetTag + '\'' +
                ", manufacturer='" + manufacturer + '\'' +
                ", model='" + model + '\'' +
                ", serialNumber='" + serialNumber + '\'' +
                ", UUID='" + UUID + '\'' +
                ", partNumber='" + partNumber + '\'' +
                ", hostName='" + hostName + '\'' +
                ", HostingRole='" + hostingRole + '\'' +
                ", systemType='" + systemType + '\'' +
                ", powerState='" + powerState + '\'' +
                ", status=" + status +
                ", powerRestorePolicyType='" + powerRestorePolicyType + '\'' +
                ", indicatorLED='" + indicatorLED + '\'' +
                ", boot=" + boot +
                ", biosVersion='" + biosVersion + '\'' +
                ", trustedModules='" + trustedModules + '\'' +
                ", processorSummary=" + processorSummary +
                ", memorySummary=" + memorySummary +
                ", oem=" + oem +
                '}';
    }

    public static class Actions {

        private String target;

        @JsonProperty("ResetType@Redfish.AllowableValues")
        private List<String> allowValues;

        @JsonProperty("#ComputerSystem.Reset")
        private ComputerSystemReset computerSystemReset;

        @JsonProperty("Oem")
        private HuaweiSystemsOem oem;

        public String getTarget() {
            return this.target;
        }

        public void setTarget(String target) {
            this.target = target;
        }

        public List<String> getAllowValues() {
            return this.allowValues;
        }

        public void setAllowValues(List<String> allowValues) {
            this.allowValues = allowValues;
        }

        public ComputerSystemReset getComputerSystemReset() {
            return this.computerSystemReset;
        }

        public void setComputerSystemReset(ComputerSystemReset computerSystemReset) {
            this.computerSystemReset = computerSystemReset;
        }

        public HuaweiSystemsOem getOem() {
            return this.oem;
        }

        public void setOem(HuaweiSystemsOem oem) {
            this.oem = oem;
        }

        @JsonRootName("#ComputerSystem.Reset")
        public static class ComputerSystemReset {

            private String target;
            @JsonProperty("@Redfish.ActionInfo")
            private String actionInfo;

            public String getTarget() {
                return this.target;
            }

            public void setTarget(String target) {
                this.target = target;
            }

            public String getActionInfo() {
                return this.actionInfo;
            }

            public void setActionInfo(String actionInfo) {
                this.actionInfo = actionInfo;
            }
        }

        @JsonRootName("Oem")
        public static class HuaweiSystemsOem {

            @JsonProperty("Huawei")
            private Huawei huawei;

            public Huawei getHuawei() {
                return this.huawei;
            }

            public void setHuawei(Huawei huawei) {
                this.huawei = huawei;
            }

            public static class Huawei {

                @JsonProperty("#ComputerSystem.FruControl")
                private FruControl fruControl;

                public FruControl getFruControl() {
                    return this.fruControl;
                }

                public void setFruControl(FruControl fruControl) {
                    this.fruControl = fruControl;
                }

                @JsonRootName("#ComputerSystem.FruControl")
                public static class FruControl {
                    private String target;
                    @JsonProperty("@Redfish.ActionInfo")
                    private String actionInfo;

                    public String getTarget() {
                        return this.target;
                    }

                    public void setTarget(String target) {
                        this.target = target;
                    }

                    public String getActionInfo() {
                        return this.actionInfo;
                    }

                    public void setActionInfo(String actionInfo) {
                        this.actionInfo = actionInfo;
                    }
                }
            }
        }
    }

    @JsonRootName("Oem")
    public static class SystemsOem {

        @JsonProperty("BMC")
        private SystemsBmc bmc;

        @JsonProperty("Huawei")
        private SystemsHuawei huawei;

        public SystemsBmc getBmc() {
            return this.bmc;
        }

        public SystemsHuawei getHuawei() {
            return this.huawei;
        }

        @JsonRootName("BMC")
        public static class SystemsBmc {
            /**
             * 系统资源的BMC版本
             */
            @JsonProperty("BMCVersion")
            private String bmcVersion;
            /**
             * 系统资源的CPLD版本
             */
            @JsonProperty("CPLDVersion")
            private String cpldVersion;
            /**
             * 系统资源的ME 版本
             */
            @JsonProperty("MEVersion")
            private String meVersion;
            /**
             * 系统资源的PSU版本
             */
            @JsonProperty("PSUVersion")
            private String psuVersion;
            /**
             * 自定义的典配模型
             */
            @JsonProperty("ConfigurationModel")
            private String configurationModel;

            public String getBmcVersion() {
                return this.bmcVersion;
            }

            public String getCpldVersion() {
                return this.cpldVersion;
            }

            public String getMeVersion() {
                return this.meVersion;
            }

            public String getPsuVersion() {
                return this.psuVersion;
            }

            public String getConfigurationModel() {
                return this.configurationModel;
            }
        }

        @JsonRootName("Huawei")
        public static class SystemsHuawei {
            private String OSVersion;
            private String KernalVersion;
            private String MajorOSVersion;
            private String MinorOSVersion;
            private String MajorPatchVersion;
            private String MinorPatchVersion;
            private String DomainName;
            private String HostDescription;
            private int NetBandwidthThresholdPercent;
            private boolean LocalKvmEnabled;
            private List<String> PartitionLists;
            private int CPUUsagePercent;
            private int MemoryUsagePercent;
            private int CPUThresholdPercent;
            private int MemoryThresholdPercent;
            private int HardDiskThresholdPercent;
            private int SafePowerOffTimoutSeconds;
            private String PowerOnStrategy;
            private String SlotWidth;
            private String ProductAlias;
            private String ProductVersion;
            private String DeviceOwnerID;
            private int DeviceSlotID;
            private List<String> BootupSequence;
            private SwitchIpInfo SwitchIpInfo;
            private String PchModel;
            private boolean BootModeChangeEnabled;

            public static class SwitchIpInfo {
                @JsonProperty("Base")
                private String base;
                @JsonProperty("Fabric")
                private String fabric;
                @JsonProperty("FC")
                private String fc;

                public String getBase() {
                    return this.base;
                }

                public String getFabric() {
                    return this.fabric;
                }

                public String getFc() {
                    return this.fc;
                }
            }
        }
    }
}
